﻿using System;
using UnityEngine;
using UnityEngine.UI;
using static System.Net.Mime.MediaTypeNames;

public class MomentPhotoItem : MonoBehaviour
{
    public NetworkImage networkPhoto;

    Texture2D m_Texture2D;
    public Texture2D texture2D => m_Texture2D;

    public GameObject closeBtn;

    void Awake()
    {
    }

    public void Init(Texture2D tex)
    {
        if (m_Texture2D)
            DestroyImmediate(m_Texture2D);
        m_Texture2D = tex;

        networkPhoto.InitWithData(new Tex(tex.EncodeToJPG(80),tex.width,tex.height));
    }
    public void Init(string tex,Action onInitTexEnd = null)
    {
        networkPhoto.Init(tex, onInitTexEnd);

        if (closeBtn)
            closeBtn.SetActive(tex != null);
    }

    public Vector2 SetImgSize(float size)
    {
        return this.networkPhoto.SetImgSize(size);
    }

    public void OnClick()
    {
        GameDebug.Log($"MomentPhotoItem -> OnClick");
    }

    public Action<MomentPhotoItem> onClickClose;
    public void OnClickClose()
    {
        onClickClose?.Invoke(this);
    }
}